package net.atomtree.handler.test;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by czk on 2016/1/3.
 */
public class JSONtest {
    public static void main(String[] args) {
        String jsonValue="[ {\n" +
                "  \"status\" : \"ACTIVE\",\n" +
                "  \"stageId\" : 2,\n" +
                "  \"attemptId\" : 0,\n" +
                "  \"numActiveTasks\" : 2,\n" +
                "  \"numCompleteTasks\" : 0,\n" +
                "  \"numFailedTasks\" : 0,\n" +
                "  \"executorRunTime\" : 0,\n" +
                "  \"inputBytes\" : 0,\n" +
                "  \"inputRecords\" : 0,\n" +
                "  \"outputBytes\" : 0,\n" +
                "  \"outputRecords\" : 0,\n" +
                "  \"shuffleReadBytes\" : 0,\n" +
                "  \"shuffleReadRecords\" : 0,\n" +
                "  \"shuffleWriteBytes\" : 0,\n" +
                "  \"shuffleWriteRecords\" : 0,\n" +
                "  \"memoryBytesSpilled\" : 0,\n" +
                "  \"diskBytesSpilled\" : 0,\n" +
                "  \"name\" : \"map at TestRDD.scala:14\",\n" +
                "  \"details\" : \"org.apache.spark.rdd.RDD.map(RDD.scala:293)\\nTest.TestRDD$.main(TestRDD.scala:14)\\nTest.TestRDD.main(TestRDD.scala)\\nTest.runtest.main(runtest.java:7)\\nsun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\\nsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\\nsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\njava.lang.reflect.Method.invoke(Method.java:606)\\norg.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:665)\\norg.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:170)\\norg.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:193)\\norg.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:112)\\norg.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)\",\n" +
                "  \"schedulingPool\" : \"default\",\n" +
                "  \"accumulatorUpdates\" : [ ]\n" +
                "}, {\n" +
                "  \"status\" : \"COMPLETE\",\n" +
                "  \"stageId\" : 1,\n" +
                "  \"attemptId\" : 0,\n" +
                "  \"numActiveTasks\" : 0,\n" +
                "  \"numCompleteTasks\" : 2,\n" +
                "  \"numFailedTasks\" : 0,\n" +
                "  \"executorRunTime\" : 13452,\n" +
                "  \"inputBytes\" : 0,\n" +
                "  \"inputRecords\" : 0,\n" +
                "  \"outputBytes\" : 0,\n" +
                "  \"outputRecords\" : 0,\n" +
                "  \"shuffleReadBytes\" : 18657130,\n" +
                "  \"shuffleReadRecords\" : 804214,\n" +
                "  \"shuffleWriteBytes\" : 19043427,\n" +
                "  \"shuffleWriteRecords\" : 802192,\n" +
                "  \"memoryBytesSpilled\" : 0,\n" +
                "  \"diskBytesSpilled\" : 0,\n" +
                "  \"name\" : \"map at TestRDD.scala:14\",\n" +
                "  \"details\" : \"org.apache.spark.rdd.RDD.map(RDD.scala:293)\\nTest.TestRDD$.main(TestRDD.scala:14)\\nTest.TestRDD.main(TestRDD.scala)\\nTest.runtest.main(runtest.java:7)\\nsun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\\nsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\\nsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\njava.lang.reflect.Method.invoke(Method.java:606)\\norg.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:665)\\norg.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:170)\\norg.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:193)\\norg.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:112)\\norg.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)\",\n" +
                "  \"schedulingPool\" : \"default\",\n" +
                "  \"accumulatorUpdates\" : [ ]\n" +
                "}, {\n" +
                "  \"status\" : \"COMPLETE\",\n" +
                "  \"stageId\" : 0,\n" +
                "  \"attemptId\" : 0,\n" +
                "  \"numActiveTasks\" : 0,\n" +
                "  \"numCompleteTasks\" : 2,\n" +
                "  \"numFailedTasks\" : 0,\n" +
                "  \"executorRunTime\" : 16887,\n" +
                "  \"inputBytes\" : 0,\n" +
                "  \"inputRecords\" : 800000,\n" +
                "  \"outputBytes\" : 0,\n" +
                "  \"outputRecords\" : 0,\n" +
                "  \"shuffleReadBytes\" : 0,\n" +
                "  \"shuffleReadRecords\" : 0,\n" +
                "  \"shuffleWriteBytes\" : 18657130,\n" +
                "  \"shuffleWriteRecords\" : 804214,\n" +
                "  \"memoryBytesSpilled\" : 0,\n" +
                "  \"diskBytesSpilled\" : 0,\n" +
                "  \"name\" : \"map at TestRDD.scala:14\",\n" +
                "  \"details\" : \"org.apache.spark.rdd.RDD.map(RDD.scala:293)\\nTest.TestRDD$.main(TestRDD.scala:14)\\nTest.TestRDD.main(TestRDD.scala)\\nTest.runtest.main(runtest.java:7)\\nsun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\\nsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\\nsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\njava.lang.reflect.Method.invoke(Method.java:606)\\norg.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:665)\\norg.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:170)\\norg.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:193)\\norg.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:112)\\norg.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)\",\n" +
                "  \"schedulingPool\" : \"default\",\n" +
                "  \"accumulatorUpdates\" : [ ]\n" +
                "}, {\n" +
                "  \"status\" : \"PENDING\",\n" +
                "  \"stageId\" : 3,\n" +
                "  \"attemptId\" : 0,\n" +
                "  \"numActiveTasks\" : 0,\n" +
                "  \"numCompleteTasks\" : 0,\n" +
                "  \"numFailedTasks\" : 0,\n" +
                "  \"executorRunTime\" : 0,\n" +
                "  \"inputBytes\" : 0,\n" +
                "  \"inputRecords\" : 0,\n" +
                "  \"outputBytes\" : 0,\n" +
                "  \"outputRecords\" : 0,\n" +
                "  \"shuffleReadBytes\" : 0,\n" +
                "  \"shuffleReadRecords\" : 0,\n" +
                "  \"shuffleWriteBytes\" : 0,\n" +
                "  \"shuffleWriteRecords\" : 0,\n" +
                "  \"memoryBytesSpilled\" : 0,\n" +
                "  \"diskBytesSpilled\" : 0,\n" +
                "  \"name\" : \"saveAsTextFile at TestRDD.scala:16\",\n" +
                "  \"details\" : \"org.apache.spark.rdd.RDD.saveAsTextFile(RDD.scala:1383)\\nTest.TestRDD$.main(TestRDD.scala:16)\\nTest.TestRDD.main(TestRDD.scala)\\nTest.runtest.main(runtest.java:7)\\nsun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\\nsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\\nsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\njava.lang.reflect.Method.invoke(Method.java:606)\\norg.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:665)\\norg.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:170)\\norg.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:193)\\norg.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:112)\\norg.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)\",\n" +
                "  \"schedulingPool\" : \"\",\n" +
                "  \"accumulatorUpdates\" : [ ]\n" +
                "} ]";
        JSONArray jsonarray=JSONArray.fromObject(jsonValue);
        int length=jsonarray.size();
        System.out.println(length);

        List<JSONObject> container=new ArrayList<JSONObject>();

        int initJsonArrayIndex=0;
        for(int jsonArrayIndex=initJsonArrayIndex;jsonArrayIndex<length;jsonArrayIndex++){
            Object jsonArrayObject=jsonarray.get(jsonArrayIndex);
            if (null!=jsonArrayObject) {
                JSONObject json = JSONObject.fromObject(jsonArrayObject);
                container.add(json);
            }
        }

        System.out.println(container.get(3));
    }
}
